# Copyright Johanc Carlsson, 2008

import cgi
import datetime
import wsgiref.handlers

from google.appengine.ext import db
from google.appengine.ext.db import djangoforms



class User(db.Model):
    user = db.UserProperty()
    nick = db.StringProperty(multiline=False)
    email = db.StringProperty(multiline=False)
    image = db.StringProperty(multiline=False)
    facebook_id = db.StringProperty(multiline=False)
    facebook_image = db.StringProperty(multiline=False)
    twitter_id = db.StringProperty(multiline=False)
    twitter_image = db.StringProperty(multiline=False)
    my_tags = db.StringListProperty()
    created = db.DateTimeProperty(auto_now_add=True)
    updated = db.DateTimeProperty(auto_now=True)

class UserAddForm(djangoforms.ModelForm):
  class Meta:
    model = User
    exclude = ['created', 'updated']
class UserEditForm(djangoforms.ModelForm):
  class Meta:
    model = User
    exclude = ['created', 'updated']

class Friend(db.Model):
    user = db.ReferenceProperty(User, collection_name='my_friends')
    friend = db.ReferenceProperty(User, collection_name='friends_of_mine')
    nick = db.StringProperty(multiline=False)
    image = db.StringProperty(multiline=False)
    relation = db.StringProperty(multiline=False)
    created = db.DateTimeProperty(auto_now_add=True)
    updated = db.DateTimeProperty(auto_now=True)

class FriendAddForm(djangoforms.ModelForm):
  class Meta:
    model = Friend
    exclude = ['created', 'updated']

class FriendEditForm(djangoforms.ModelForm):
  class Meta:
    model = Friend
    exclude = ['created', 'updated']


class IouUome(db.Model):
    user = db.ReferenceProperty(User, collection_name='my_ious')
    user_nick = db.StringProperty(multiline=False)
    user_image = db.StringProperty(multiline=False)
    friend = db.ReferenceProperty(User, collection_name='my_uomes')
    friend_nick = db.StringProperty(multiline=False)
    friend_image = db.StringProperty(multiline=False)
    what = db.StringProperty(multiline=True)
    tags = db.CategoryProperty()
    amount = db.IntegerProperty()
    unit = db.StringProperty(multiline=False)
    created = db.DateTimeProperty(auto_now_add=True)
    updated = db.DateTimeProperty(auto_now=True)

class IouUomeAddForm(djangoforms.ModelForm):
  class Meta:
    model = IouUome
    exclude = ['created', 'updated']

class IouUomeEditForm(djangoforms.ModelForm):
  class Meta:
    model = IouUome
    exclude = ['created', 'updated']



class IouUomeCounterByFriend(db.Model):
    user = db.ReferenceProperty(User, collection_name='my_ious_by_friends_counts')
    friend = db.ReferenceProperty(User, collection_name='my_uomes_by_friends_counts')
    friend_nick = db.StringProperty(multiline=False)
    friend_image = db.StringProperty(multiline=False)
    count = db.IntegerProperty()    
    updated = db.DateTimeProperty(auto_now=True)

class LeechCounter(db.Model):
    #Number of IouUome where user is friend
    friend = db.ReferenceProperty(User, collection_name='my_leech_counter')
    friend_nick = db.StringProperty(multiline=False)
    friend_image = db.StringProperty(multiline=False)
    count = db.IntegerProperty()    
    updated = db.DateTimeProperty(auto_now=True)

class SaintCounter(db.Model):
    #Number of IouUome where user is user
    user = db.ReferenceProperty(User, collection_name='my_saint_counter')
    user_nick = db.StringProperty(multiline=False)
    user_image = db.StringProperty(multiline=False)
    count = db.IntegerProperty()    
    updated = db.DateTimeProperty(auto_now=True)

class FriendsCounter(db.Model):
    user = db.ReferenceProperty(User, collection_name='my_friends_counter')
    count = db.IntegerProperty()    
    updated = db.DateTimeProperty(auto_now=True)

class AmountSumByFriend(db.Model):
    user = db.ReferenceProperty(User, collection_name='my_amount_sum_by_friends_counter')
    friend = db.ReferenceProperty(User, collection_name='my_friends_amount_sum_counters')
    friend_nick = db.StringProperty(multiline=False)
    friend_image = db.StringProperty(multiline=False)
    unit = db.StringProperty(multiline=False)
    count = db.IntegerProperty()    
    updated = db.DateTimeProperty(auto_now=True)

class AmountSumTotal(db.Model):
    user = db.ReferenceProperty(User, collection_name='my_amount_sum_total_counters')
    unit = db.StringProperty(multiline=False)
    count = db.IntegerProperty()    
    updated = db.DateTimeProperty(auto_now=True)



